import upload from '@dfeidao/atom-web/file/upload';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import get from '@dfeidao/atom-web/local/get';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import { file_url, spaceid } from '../../atom/config';

export default async function a004(fd: IFeidaoAiBrowserComponent) {
	const staff_no = get(fd, 'staff_no');
	const productid = get(fd, 'productid');
	const form_add = fd.data.node.querySelector<HTMLInputElement>('#xiugaitouxiang');
	const res_upload = await upload(spaceid, form_add);
	const headimg = res_upload.filename;
	const res = await nodejs<{ code: number }>('common/zjc-000003/s001', { staff_no, productid, headimg });
	if (res.code) {
		document.getElementsByName('touxiang').forEach((v: HTMLImageElement) => {
			v.src = file_url + 'getfile?productid=' + spaceid + '&id=' + headimg;
		});
		success('修改头像成功');
	} else {
		error('修改头像成功');
	}
}
